
export function getRouterTableData() {
  const data = sessionStorage.getItem('ROUTER_TABLE')
  return data !== null ? JSON.parse(data) : []
}

export function getActiveKeyData() {
  const data = sessionStorage.getItem('ACTIVE_KEY')
  return data !== null ? data : ""
}

export function setRouterTableData(arr) {
  sessionStorage.setItem('ROUTER_TABLE', arr)
}

export function setActiveKeyData(Key) {
  sessionStorage.setItem('ACTIVE_KEY', Key)
}

const state = {
  panes: [],
  activeKey: ""
}
const mutations = {
  CHANGE_PANES: (state, data) => {
    const arr = state.panes.filter(
      (item, i) => item.path === data.path
    );
    if (arr.length == 0) {
      state.panes.push(data)
      // setRouterTableData(state.panes)
    }
  },
  CHANGE_ACTIVEKEY: (state, data) => {
    // console.log(data, 'CHANGE_ACTIVEKEY')
    setActiveKeyData(data)
    state.activeKey = data
  },
  REMOVE_SET_PANES: (state, data) => {
    state.panes = data
  },
}

const actions = {
  changePanes({ commit }, data) {
    commit('CHANGE_PANES', data)
  },
  changeActiveKey({ commit }, data) {
    commit('CHANGE_ACTIVEKEY', data)
  },
  removeSetPanes({ commit }, data) {
    commit('REMOVE_SET_PANES', data)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

